package com.happe.foodeasy.service.impl;

import com.happe.foodeasy.dao.CustomerDao;
import com.happe.foodeasy.dto.CustomerDto;
import com.happe.foodeasy.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("customerService")
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerDao customerDao;

    @Override
    public boolean checkUsernameExist(String username) {
        CustomerDto param = new CustomerDto();
        param.setUsername(username);
        List<CustomerDto> targetCustomers = customerDao.retrieveByParam(param);
        return targetCustomers.size() > 0;
    }

    @Override
    public void saveOne(CustomerDto customerDto) {
        customerDao.saveOne(customerDto);
    }

    @Override
    public boolean checkUserExist(CustomerDto customerDto) {
        List<CustomerDto> result = customerDao.retrieveByParam(customerDto);
        return result.size() > 0;
    }

    @SuppressWarnings("all")
    public void setCustomerDao(CustomerDao customerDao) {
        this.customerDao = customerDao;
    }
}
